package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LaneKey;
import com.ruoyi.system.service.ILanekeyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 按键记录Controller
 * 
 * @author ruoyi
 * @date 2025-04-17
 */
@Controller
@RequestMapping("/system/lanekey")
public class LaneKeyController extends BaseController
{
    private String prefix = "system/lanekey";

    @Autowired
    private ILanekeyService lanekeyService;

    @RequiresPermissions("system:lanekey:view")
    @GetMapping()
    public String lanekey()
    {
        return prefix + "/lanekey";
    }

    /**
     * 查询按键记录列表
     */
    @RequiresPermissions("system:lanekey:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LaneKey lanekey)
    {
        startPage();
        List<LaneKey> list = lanekeyService.selectLanekeyList(lanekey);
        return getDataTable(list);
    }

    /**
     * 导出按键记录列表
     */
    @RequiresPermissions("system:lanekey:export")
    @Log(title = "按键记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LaneKey lanekey)
    {
        List<LaneKey> list = lanekeyService.selectLanekeyList(lanekey);
        ExcelUtil<LaneKey> util = new ExcelUtil<LaneKey>(LaneKey.class);
        return util.exportExcel(list, "按键记录数据");
    }

    /**
     * 新增按键记录
     */
    @RequiresPermissions("system:lanekey:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存按键记录
     */
    @RequiresPermissions("system:lanekey:add")
    @Log(title = "按键记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LaneKey lanekey)
    {
        return toAjax(lanekeyService.insertLanekey(lanekey));
    }

    /**
     * 修改按键记录
     */
    @RequiresPermissions("system:lanekey:edit")
    @GetMapping("/edit/{tradeId}")
    public String edit(@PathVariable("tradeId") String tradeId, ModelMap mmap)
    {
        LaneKey lanekey = lanekeyService.selectLanekeyByTradeId(tradeId);
        mmap.put("lanekey", lanekey);
        return prefix + "/edit";
    }

    /**
     * 修改保存按键记录
     */
    @RequiresPermissions("system:lanekey:edit")
    @Log(title = "按键记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LaneKey lanekey)
    {
        return toAjax(lanekeyService.updateLanekey(lanekey));
    }

    /**
     * 删除按键记录
     */
    @RequiresPermissions("system:lanekey:remove")
    @Log(title = "按键记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lanekeyService.deleteLanekeyByTradeIds(ids));
    }
}
